package com.equipment;

import com.util.EncodingUtil;

/**
 * C8 OBU交易
 * @author liuyadong
 *
 */
public class OBUTransactionRequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "C8"; // 扩展代码
	private String VerifyMac2 = "00";//是否效验MAC2，0表示不效验，1表示效验 0
	public static String TradeTime = "";   //交易时间BCD，年月日时分秒
	public static String TradeMoney = ""; //交易金额
	private String TradeInfo = ""; //0019文件内容，不包括AA2900

	private String BCC = ""; // 异或校验值

	/**
	 * 拼接C7指令
	 * @return
	 */
	public String command(String verifyMac2,String tradeTime,String tradeMoney,String tradeInfo) {
		this.VerifyMac2 = verifyMac2;
		TradeTime = tradeTime;
		TradeMoney = tradeMoney;
		this.TradeInfo = tradeInfo;
		// 计算长度
		Length = EncodingUtil.desToHex((broadening+VerifyMac2+TradeTime+TradeMoney+TradeInfo).length() / 2, 4);
		// 异或校验从RSCTL到DATA所有字节的异或值
		String DATA = RSCTL + Length + code + broadening +VerifyMac2+TradeTime+TradeMoney+TradeInfo;
		// 异或校验从RSCTL到DATA所有字节的异或值
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		// 拼接完整的请求
		String retn = STX + DATA + BCC;
		return retn;
	}

}
